<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">click</button>
    <h1 id="h1"></h1>
    
</body>
<script>
    function createXMLHttpRequest(){
        try{
            return new XMLHttpRequest();
        }catch(e){
            try {
                return ActiveXObject("Msxml2.XMLHTTP");
            } catch (error) {
                try {
                    return ActiveXObject("Microsoft.XMLHTTP");
                } catch (error) {
                    throw error;
                }
            }
        }
    }
    window.onload = function(){
        // 得到 btn 元素
        var btn = document.getElementById("btn");
        btn.onclick = function() {
            let xmlHttp = createXMLHttpRequest();

            xmlHttp.open("GET", `<c:url value='/AServlet'/>`, true);

            xmlHttp.send(null); // GET 请求没有请求体，但是也要给出 null

            xmlHttp.onreadystatechange = funciton() {
                if(xmlHttp.readState == 4 && xmlHttp.status == 200){
                    var text = xml.responseText;
                    var h1 = document.getElementById("h1");
                    h1.innerHTML = text;
                }
            }

        }
    };
</script>
</html>